/*
 * @Author: Du Weixing duweixing@sgsimulation.com
 * @Date: 2024-10-19 16:29:55
 * @LastEditors: Du Weixing duweixing@sgsimulation.com
 * @LastEditTime: 2024-12-07 14:06:27
 * @FilePath: \SGFEM\Solver\SectionCalculator\BeamSection\FormulaMethod\src\RodBeamSectionFormulaCalculator.cpp
 * @Description: PBEAML 圆形（ROD）梁截面属性使用解析公式计算类
 * 
 * Copyright (c) 2024 by 神工仿真, All Rights Reserved. 
 */

#include "RodBeamSectionFormulaCalculator.h"
#include <cmath>
#include <cstring>
#include "Utility/Algebra/Point.h"
#include "DataStructure/Common/Constant.h"
#include "DataStructure/Input/Property/PBARLData.h"
#include "DataStructure/Input/Property/PBARData.h"
#include "../Bar/RodSectionFormulaCalculator.h"

using SG::Algebra::Point;
using SG::DataStructure::Common::TOLERANCE;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBEAMLData;
using SG::DataStructure::FEM::PBARData;
using SG::DataStructure::FEM::PBEAMData;
using SG::FEMSolver::Element::RodSectionFormulaCalculator;
using SG::FEMSolver::Element::RodBeamSectionFormulaCalculator;

PBEAMData RodBeamSectionFormulaCalculator::Compute (const PBEAMLData& pBeamL) const
{
    PBEAMData pBeam;

    if (!std::strcmp (pBeamL.m_group, "MSCBML0"))
    {
        auto section = pBeamL.m_section;
        auto n       = section.size ();

        pBeam.m_id  = pBeamL.m_id;
        pBeam.m_mId = pBeamL.m_mId;

        // 恒截面 NSEGS CCF SECTION_LEN
        // 恒截面 1     1   2
        // 变截面 1     2   3
        // 变截面 2     0   4
        // 变截面 9     0   11
        // 变截面 10    0   11
        if (2 == n)
        {
            pBeam.m_nsges = 1;
        }
        else if (n > 2 && n < 11)
        {
            pBeam.m_nsges = n - 2;
        }
        else if (11 == n)
        {
            if (std::fabs (section[9].m_rdist - 1.0) < TOLERANCE)
            {
                pBeam.m_nsges = 9;
            }
            else
            {
                pBeam.m_nsges = 10;
            }
        }

        if (2 == n)
        {
            pBeam.m_ccf = 1;

        }
        else if (3 == n)
        {
            pBeam.m_ccf = 2;
        }

        auto nCompute = pBeam.m_nsges <= pBeam.m_ccf ? pBeam.m_ccf : pBeam.m_nsges + 1;
        PBARLData pBarL;
        PBARData pBar;
        Point centroid;
        for (size_t i = 0; i < nCompute; ++i)
        {
            pBarL.m_dimension = section[i].m_dims;
            RodSectionFormulaCalculator calculator;
            calculator.Compute (pBarL, _OUT pBar, _OUT centroid);

            pBeam.m_SO[i]  = section[i].m_so; // ToDo：变量名称大小
            pBeam.m_XXB[i] = section[i].m_rdist;
            pBeam.m_A[i]   = pBar.m_A;
            pBeam.m_I1[i]  = pBar.m_I1;
            pBeam.m_I2[i]  = pBar.m_I2;
            pBeam.m_I12[i] = pBar.m_I12;
            pBeam.m_J[i]   = pBar.m_J;
            pBeam.m_NSM[i] = section[i].m_nsm; // ToDo：变量名称大小

            pBeam.m_C1[i]  = pBar.m_C1;
            pBeam.m_C2[i]  = pBar.m_C2;
            pBeam.m_D1[i]  = pBar.m_D1;
            pBeam.m_D2[i]  = pBar.m_D2;
            pBeam.m_E1[i]  = pBar.m_E1;
            pBeam.m_E2[i]  = pBar.m_E2;
            pBeam.m_F1[i]  = pBar.m_F1;
            pBeam.m_F2[i]  = pBar.m_F2;
        }
        if (nCompute != 11)
        {
            pBeam.m_SO[10]  = pBeam.m_SO[nCompute - 1];
            pBeam.m_XXB[10] = 1.0;
            pBeam.m_A[10]   = pBeam.m_A[nCompute - 1];
            pBeam.m_I1[10]  = pBeam.m_I1[nCompute - 1];
            pBeam.m_I2[10]  = pBeam.m_I2[nCompute - 1];
            pBeam.m_I12[10] = pBeam.m_I12[nCompute - 1];
            pBeam.m_J[10]   = pBeam.m_J[nCompute - 1];
            pBeam.m_NSM[10] = pBeam.m_NSM[nCompute - 1];

            pBeam.m_C1[10]  = pBeam.m_C1[nCompute - 1];
            pBeam.m_C2[10]  = pBeam.m_C2[nCompute - 1];
            pBeam.m_D1[10]  = pBeam.m_D1[nCompute - 1];
            pBeam.m_D2[10]  = pBeam.m_D2[nCompute - 1];
            pBeam.m_E1[10]  = pBeam.m_E1[nCompute - 1];
            pBeam.m_E2[10]  = pBeam.m_E2[nCompute - 1];
            pBeam.m_F1[10]  = pBeam.m_F1[nCompute - 1];
            pBeam.m_F2[10]  = pBeam.m_F2[nCompute - 1];
        }

        pBeam.m_K1  = 0.9;
        pBeam.m_K2  = 0.9;
        pBeam.m_CWA = 0.0; // ToDo
        pBeam.m_CWB = 0.0; // ToDo
    }

    return pBeam;
}